import {
    UserOutlined,
    HomeOutlined,
    ShopOutlined,
    DeploymentUnitOutlined,
    TagsOutlined,
    DatabaseOutlined,
    SafetyOutlined,
    InboxOutlined,
    EnvironmentOutlined,
    ContainerOutlined
} from '@ant-design/icons'
// 导航
export const menuItems = [
    {
        key: '/admin',
        icon: <HomeOutlined/>,
        label: '首页',
        role: ['admin', 'seller']
    },
    {
        key: '/admin/seller',
        icon: <InboxOutlined/>,
        label: '商家管理',
        role: ['admin'],
        children: [
            {
                key: '/admin/seller/verify',
                label: '商家审核',
                role: ['admin']
            },
            {
                key: '/admin/seller/list',
                label: '商家列表',
                role: ['admin']
            }
        ]
    },
    {
        key: '/admin/shop',
        icon: <ShopOutlined/>,
        label: '店铺管理',
        role: ['seller'],
        children: [
            {
                key: '/admin/shop/list',
                label: '店铺列表',
                role: ['seller']
            },
            {
                key: '/admin/shop/qrcode',
                label: '二维码管理',
                role: ['seller']
            }
        ]
    },
    {
        key: '/admin/content',
        icon: <DeploymentUnitOutlined/>,
        label: '内容管理',
        role: ['seller'],
        children: [
            {
                key: '/admin/content/category',
                label: '文章分类',
                role: ['seller']
            },
            {
                key: '/admin/content/article',
                label: '文章列表',
                role: ['seller']
            },
            {
                key: '/admin/content/twitter',
                label: '推文创作',
                role: ['seller']
            }
        ]
    },
    {
        key: '/admin/user',
        icon: <UserOutlined/>,
        label: '用户管理',
        role: ['seller'],
        children: [
            {
                key: '/admin/user/list',
                label: '用户列表',
                role: ['seller']
            },
            {
                key: '/admin/user/crowd',
                label: '人群管理',
                role: ['seller']
            }
        ]
    },
    {
        key: '/admin/market',
        icon: <EnvironmentOutlined/>,
        label: '营销管理',
        role: ['seller'],
        children: [
            {
                key: '/admin/market/activaty',
                label: '活动管理',
                role: ['seller']
            },
            {
                key: '/admin/market/coupon',
                label: '优惠券管理',
                role: ['seller']
            },
            {
                key: '/admin/market/receive',
                label: '领取记录',
                role: ['seller']
            },
            {
                key: '/admin/market/link',
                label: '链接管理',
                role: ['seller']
            }
        ]
    },
    {
        key: '/admin/touchReach',
        icon: <SafetyOutlined/>,
        label: '触达管理',
        role: ['admin', 'seller'],
        children: [
            {
                key: '/admin/touchReach/timedMsg',
                label: '定时消息',
                role: ['seller']
            },
            {
                key: '/admin/touchReach/triggerMsg',
                label: '触发消息',
                role: ['admin']
            },
            {
                key: '/admin/touchReach/timedPush',
                label: '定时推送',
                role: ['seller']
            },
            {
                key: '/admin/touchReach/behaviorTrigger',
                label: '行为触发',
                role: ['admin']
            }
        ]
    },
    {
        key: '/admin/tag',
        icon: <TagsOutlined/>,
        label: '标签管理',
        role: ['admin'],
        children: [
            {
                key: '/admin/tag/list',
                label: '标签列表',
                role: ['admin']
            }
        ]
    },
    {
        key: '/admin/privilege',
        icon: <ContainerOutlined/>,
        label: '权限管理',
        role: ['admin'],
        children: [
            {
                key: '/admin/privilege/account',
                label: '账号管理',
                role: ['admin']
            }
            // {
            //   key: '/admin/privilege/role',
            //   label: '角色管理',
            //   role: ['admin']
            // },
            // {
            //   key: '/admin/privilege/source',
            //   label: '资源管理',
            //   role: ['admin']
            // }
        ]
    }
    // {
    //   key: '/admin/statistics',
    //   icon: <DatabaseOutlined />,
    //   label: '数据统计',
    //   role: ['admin'],
    //   children: [
    //     {
    //       key: '/admin/statistics/operation',
    //       label: '运营数据',
    //       role: ['admin']
    //     }
    //   ]
    // }
]

// 递归获取所有平台的菜单权限
function allAdminMenuItems(menuItems) {
    const adminMenuItems = []
    for (const menuItem of menuItems) {
        if (menuItem.role.includes('admin')) {
            const newMenuItem = {...menuItem}
            delete newMenuItem.role

            if (newMenuItem.children) {
                newMenuItem.children = allAdminMenuItems(newMenuItem.children)
            }

            adminMenuItems.push(newMenuItem)
        }
    }
    return adminMenuItems
}

// 递归获取所有商家的菜单权限
function allSellerMenuItems(menuItems) {
    const adminMenuItems = []
    for (const menuItem of menuItems) {
        if (menuItem.role.includes('seller')) {
            const newMenuItem = {...menuItem}
            delete newMenuItem.role

            if (newMenuItem.children) {
                newMenuItem.children = allSellerMenuItems(newMenuItem.children)
            }

            adminMenuItems.push(newMenuItem)
        }
    }
    return adminMenuItems
}

export const sellerMenuItems = allSellerMenuItems(menuItems)
export const adminMenuItems = allAdminMenuItems(menuItems)
